<?php
function get_url() {
	$sys_protocal = isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == '443' ? 'https://' : 'http://';$php_self = $_SERVER['PHP_SELF'] ? $_SERVER['PHP_SELF'] : $_SERVER['SCRIPT_NAME'];$path_info = isset($_SERVER['PATH_INFO']) ? $_SERVER['PATH_INFO'] : '';$relate_url = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : $php_self.(isset($_SERVER['QUERY_STRING']) ? '?'.$_SERVER['QUERY_STRING'] : $path_info);return $sys_protocal.(isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : '').$relate_url;
}
/**
 * 判断性别
 * @param  int $sex 出入的参数数字
 * @return string   返回的字符串 
 */
function getsex($sex)
{
	if($sex == 0){
		return '未知';
	};
	if($sex == 1){
		return '男';
	};
	if($sex == 2){
		return '女';
	};

}

/**
 * 格式化字节大小
 * @param  number $size      字节数
 * @param  string $delimiter 数字和单位分隔符
 * @return string            格式化后的带单位的大小
 */
function format_bytes($size, $delimiter = '') {
    $units = array('B', 'KB', 'MB', 'GB', 'TB', 'PB');
    for ($i = 0; $size >= 1024 && $i < 5; $i++) $size /= 1024;
    return round($size, 2) . $delimiter . $units[$i];
}




	function responseText($postObj,$Content){
	        $FromUserName = $postObj->ToUserName;
	        $ToUserName   = $postObj->FromUserName;
	        $MsgType = 'text';
	        $CreateTime = time();
	        $template = "<xml>
	                            <ToUserName><![CDATA[%s]]></ToUserName>
	                            <FromUserName><![CDATA[%s]]></FromUserName>
	                            <CreateTime>%s</CreateTime>
	                            <MsgType><![CDATA[%s]]></MsgType>
	                            <Content><![CDATA[%s]]></Content>
	                            </xml>";
	        $info = sprintf($template,$ToUserName,$FromUserName,$CreateTime,$MsgType,$Content);
	        echo $info;
    }
    //回复图文消息
    function responseNews($postObj,$array){
        $ToUserName = $postObj->FromUserName;
        $FromUserName = $postObj->ToUserName;
        $CreateTime = time();
        $MsgType = 'news';
        $template = "<xml>
                            <ToUserName><![CDATA[%s]]></ToUserName>
                            <FromUserName><![CDATA[%s]]></FromUserName>
                            <CreateTime>%s</CreateTime>
                            <MsgType><![CDATA[%s]]></MsgType>
                            <ArticleCount>".count($array)."</ArticleCount>
                            <Articles>";
        foreach($array as $key=>$value){
            $template .="<item>
                                <Title><![CDATA[".$value['title']."]]></Title>
                                <Description><![CDATA[".$value['description']."]]></Description>
                                <PicUrl><![CDATA[".$value['picUrl']."]]></PicUrl>
                                <Url><![CDATA[".$value['url']."]]></Url>
                                </item>";
        }
        $template .="</Articles>
                            </xml> ";
        $info = sprintf( $template, $ToUserName, $FromUserName, $CreateTime, $MsgType );
        echo $info;
    }